package design_pattern.FactoryModelUse.Factory;

import design_pattern.FactoryModelUse.Product.QueryInfo;
import design_pattern.FactoryModelUse.Product.User;

/**
 * @Description
 * @Author yangshunjie
 * @Date 2021/9/20
 */
public abstract class UserFactory {

    /**
     * 子类自定义
     */
    protected abstract User moreBuilder(QueryInfo info);

    private void checkUser(QueryInfo info){
        if(info==null){
            throw new RuntimeException();
        }
    }

    public User createUser(QueryInfo info){
        //参数校验
        this.checkUser(info);
        //创建对象
        User user = this.moreBuilder(info);
        //父类的构造逻辑，如果没有传入memberId，就从数据库中找。
        user.setUserId(info.getUserId());
        if(info.getMemberId()==null){
            //数据库查询
            user.setMemberId("(输出数据库查询结果)");
        }else{
            user.setMemberId(info.getMemberId());
        }
        return user;
    }

}
